<?php

namespace App\Trip\Orders\BookOrders\Params;

use App\Models\Task\SnapTasks\SnapTask;
use App\Trip\Orders\BookOrders\SnapUp\SnapUpData;

class SnapParam
{
    private array $snap_param;

    public function __construct(array $param)
    {
        $this->snap_param = $param;
    }

    /**
     * 分钟
     *
     * @return int
     */
    public function getStopTime(): int
    {
        if ($this->getTaskInfo()) {
            return $this->getTaskInfo()->getStopTime();
        }
        return $this->snap_param['stop_time'];
    }

    /**
     * 编辑任务时使用
     *
     * @return SnapTask|null
     */
    public function getTaskInfo(): ?SnapTask
    {
        return $this->snap_param['task_info'] ?? null;
    }

    public function getSnapLevelServiceFee(): float
    {
        $snap_data = new SnapUpData();
        if ($this->isHighLevel()) {
            return $snap_data->TrainSnapHighSpeedServiceFee();
        } else {
            return $snap_data->TrainSnapLowSpeedServiceFee();
        }

    }

    public function isHighLevel(): bool
    {
        return $this->getSnapLevel() == SnapTask::SNAP_LEVEL_PAY_HIGH;
    }

    /**
     * 加速等级
     *
     * @return int
     */
    public function getSnapLevel(): int
    {
        if ($this->getTaskInfo()) {
            return $this->getTaskInfo()->getSnapLevel();
        }

        if (!isset($this->snap_param['snap_level'])) {
            return SnapTask::SNAP_LEVEL_LOW;
        }
        return $this->snap_param['snap_level'] == SnapTask::SNAP_LEVEL_PAY_HIGH ? SnapTask::SNAP_LEVEL_PAY_HIGH : SnapTask::SNAP_LEVEL_LOW;
    }

}